home *** CD-ROM | disk | FTP | other *** search
- Path: ts25-7.wla.ts.ucla.edu!wbayever
- From: wbayever@ucla.edu (Wayne Bayever)
- Newsgroups: comp.lang.c++
- Subject: Calling virtual functions
- Date: Sun, 18 Feb 1996 15:24:43
- Organization: UCLA
- Message-ID: <wbayever.1.000F69F7@ucla.edu>
- NNTP-Posting-Host: ts25-7.wla.ts.ucla.edu
- Keywords: pure virtual functions
- X-Newsreader: Trumpet for Windows [Version 1.0 Rev A]
-
- I have the following two class templates:
-
- /***************************************************************************
- * Class: RootFinder *
- * Purpose: Superclass for all rootfinding methods *
- ***************************************************************************/
-
- template <class T>
- class RootFinder {
- .
- .
- .
- public:
- virtual BOOL FindAllRoots(); // Calls FindRoot(complex &) several times
- virtual BOOL FindRoot(complex &root) = 0;
- };
-
- /***************************************************************************
- * Class: MullerRootFinder *
- * Purpose: Implementation of Muller's root finding method *
- ***************************************************************************/
-
- template <class T>
- class MullerRootFinder : public virtual RootFinder<T> {
- public:
- BOOL FindRoot(complex &root);
- };
-
- The function FindAllRoots() in RootFinder calls FindRoot(complex &) several
- times.
- I am using Borland C++ 3.1 to compile my program, and no errors show up. But
- when I run the program I get an error:
- Pure virtual function called
-
- My main() looks like this:
- void main() {
- .
- .
- .
- MullerRootFinder<double> mrf(14);
- .
- .
- .
- mrf.FindAllRoots(); <<<<<<<< This is the line which produces the error
-
- }
-
- Can you not call a pure virtual function from a base class function if you
- only define it in a subclass?
- I am going to derive several other root finding classes from RootFinder, I
- hope that I can do it without copying FindAllRoots() in each class.
-
- Please let me know if I am doing something wrong,
-
- Wayne Bayever
-